package com.flea.hclv.service.impl;

import com.flea.hclv.model.dao.HDriverLicenseMapper;
import com.flea.hclv.model.entity.HDriverLicense;
import com.flea.hclv.service.HDriverLicenseService;
import com.flea.system.utils.FleaStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project
 * @description: 驾驶证
 * @author: shiliqiang
 * @create: 2018-09-26 20:50
 * @version: 1.0
 */
@Service
public class HDriverLicenseServiceImpl implements HDriverLicenseService {

    @Autowired
    private HDriverLicenseMapper hDriverLicenseMapper;

    @Override
    public boolean saveOrUpdate(String userId, HDriverLicense hDriverLicense) {
        String id = hDriverLicense.getId();
        int result;
        if (id == null) {
            id = FleaStringUtils.getGenerateUUID();
            hDriverLicense.setId(id);
            hDriverLicense.setCreateUser(userId);
            hDriverLicense.setModifyUser(userId);
            result = hDriverLicenseMapper.insert(hDriverLicense);
        }else {
            hDriverLicense.setModifyUser(userId);
            result = hDriverLicenseMapper.updateByPrimaryKeySelective(hDriverLicense);
        }
        return result > 0;
    }

    @Override
    public HDriverLicense selectByDriverId(String driverId) {
        return hDriverLicenseMapper.selectByDriverId(driverId);
    }

    @Override
    public boolean deleteByIds(String userId, List<String> idList) {
        int result = hDriverLicenseMapper.deleteByIds(idList,userId);
        return result>0;
    }
}
